#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*#include <bios.h>*/
#define ShowMsg(strerror)\
{\
printf("%s\n",strerror);\
}
struct PT_tag
{

};

#ifndef _BD_
#define _BD_
int biosdisk(int a,int b,int c,int d,int e,int f,char *g)
{
    return 0;
}
#endif
int WriteMBR(char szbuffer[])
{
    if(biosdisk(3,0x80,0,0,1,1,szbuffer)==0)
    {
        ShowMsg("biosdisk write SUCCESS.");
    }
    else
    {
        ShowMsg("biosdisk write ERROR.");
        return 0;
    }
    return 1;

}
int ReadMBR(char szbuffer[])
{
    if(biosdisk(2,0x80,0,0,1,1,szbuffer)==0)
    {
        ShowMsg("biosdisk read SUCCESS.");
    }
    else
    {
        ShowMsg("biosdisk read ERROR.");
        return 0;
    }
    return 1;
}
/*扇区 柱面 磁头*/
int GetDiskSizeParaMeter(int *piHeadMax,int *piCyMAx,int *piSecMax)
{
    char szbuffer[512]={0};
    int i,j,k;

    for(i=0;i<=0xffff;i++)
    {
        if(biosdisk(2,0x80,i,0,1,1,szbuffer)!=0)
        {
            *piHeadMax=i;
            printf("Max Head:%d\n",i);
            break;
        }
    }

    for(i=0;i<=0xffff;i++)
    {
        if(biosdisk(2,0x80,0,i,1,1,szbuffer)!=0)
        {
            *piCyMAx=i;
            printf("Max Cy:%d\n",i);
            break;
        }
    }

    for(i=1;i<=0xffff;i++)
    {
        if(biosdisk(2,0x80,0,0,i,1,szbuffer)!=0)
        {
            *piSecMax=i;
            printf("Max Sector:%d\n",i);
            break;
        }
    }
    return 1;
}
int WriteMBRDPT(char szMBR[],int iEndHead,int iEndCy,int iEndSec)
{
    unsigned long ulTemp=0;
    szMBR[0x01BE]=0x80;/*引导标志*/

    szMBR[0x01BF]=0;/*开始磁头*/

    szMBR[0x01C0]=30;/*开始扇区*/
    szMBR[0x01C1]=0;/*开始柱面*/

    szMBR[0x01C2]=1;/*系统标志 1 fat32*/

    szMBR[0x01C3]=iEndHead;
    szMBR[0x01C4]=iEndSec+iEndHead&0xc0;
    szMBR[0x01C5]=(char)iEndHead&0xff;

    ulTemp=30;
    memcpy(&szMBR[0x01C6],(char*)&ulTemp,4);


    ulTemp=(iEndCy)*(iEndHead)*iEndSec-30;
    memcpy(&szMBR[0x01CA],(char*)&ulTemp,4);

}
int main()
{
    float fSize;
    char szMBR[512]={0};
    int iMaxSec,iMaxCy,iMaxHead;
    GetDiskSizeParaMeter(&iMaxHead,&iMaxCy,&iMaxSec);
    printf("Disk Size %u\n",(unsigned long)iMaxHead*(iMaxSec-1)*iMaxCy*512/1024/1024);
    getchar();
    return 0;
}
